package com.shujia.wyh.day12;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

/*
    配置文件：
    登录注册案例：
 */
public class PropertiesDemo1 {
    public static void main(String[] args) throws IOException {
        System.out.println("=====================欢迎来到吴涛婚恋介绍网！=====================");
        System.out.println("请先登录！");
        //创建键盘录入对象
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入您的用户名：");
        String username = sc.next();
        System.out.print("请输入您的密码：");
        String password = sc.next();

        //创建Properties对象
        Properties prop = new Properties();
        prop.load(new BufferedReader(new FileReader("java/src/com/shujia/wyh/day12/users.properties")));
        String username1 = prop.getProperty("username");
        String password1 = prop.getProperty("password");

        if(!username.equals(username1)){
            System.out.println("该用户不存在，请先进行注册！");
            System.out.print("请输入创建的用户名：");
            String name = sc.next();
            System.out.print("请输入创建的密码：");
            String pwd = sc.next();
            prop.setProperty("username",name);
            prop.setProperty("password",pwd);
            System.out.println("注册成功，开启婚恋之旅！");

            String username2 = prop.getProperty("username");
            String password2 = prop.getProperty("password");
            if(username.equals(username2) && password.equals(password2)){
                System.out.println("登录成功！！祝您婚姻顺利！");
            }

        }else {
            if(password.equals(password1)){
                System.out.println("登录成功！！祝您婚姻顺利！");
            }
        }
    }
}
